<?php

namespace App\Libs;

use Illuminate\Database\Eloquent\Model;

class Status
{
    //修改的ID值
    private $idValue;

    //修改状态的字段
    private $statusName;

    //修改状态的值
    private $statusValue;

    //修改的模型
    private $model;

    public function __construct(Model $model,$idValue,$statusName,$statusValue)
    {
        $this->model = $model;
        $this->idValue = $idValue;
        $this->statusName = $statusName;
        $this->statusValue = $statusValue;
    }

    public function change():bool
    {
        if(is_null($this->idValue) || is_null($this->statusName) || is_null($this->statusValue))
        {
            return false;
        }
        return $this->model->where($this->model->getKeyName(),$this->idValue)->update([$this->statusName=>$this->statusValue]);
    }

    public function getStatusModel()
    {
        return $this->model;
    }
}
